﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;
using System.IO;
using System.Data.SqlClient;
using System.Text;
using System.Threading;
using System.Web.Mvc;
using YunShop_WebAPI.BLL;
using YunShop_WebAPI.BLL.SxfPay;

namespace YunShop_WebAPI
{
    public class ResultService
    {
        public static JsonResult GetReportResultErr()
        {
            var data = "";
            object obj = new
            {
                msg = "fail",
                frowcount = 0,
                fpagesize = CommonFun.mRptPageSize,
                fpagecount = 0,
                fpageindex = 0,
                data
            };
            return new JsonResult
            {
                Data = obj,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        public static JsonResult GetReportResult(ArrayList mdata)
        {
            try
            {
                string json = PluSoft.Utils.JSON.Encode(mdata);
                int mRowcount = 0;
                int mPageindex = 0;                
                int mPagecount = 0;
                string mState = "success";
                if (mdata.Count > 0)
                {
                    Hashtable ht = mdata[0] as Hashtable;
                    mRowcount = CommonFun.ConvertToInt(ht["FRowCount"]);
                    Double sPageTotal = Math.Ceiling(CommonFun.ConvertToDouble(mRowcount) / CommonFun.ConvertToDouble(CommonFun.mRptPageSize));
                    mPagecount = Convert.ToInt32(sPageTotal);
                    mState = "success";
                }
                string dataOut = SerializerHelper.SerializeToString(mdata);
                var data = Common.ConvertToBase64String(dataOut);
                object obj = new
                {
                    msg = mState,
                    frowcount = mRowcount,
                    fpagesize = CommonFun.mRptPageSize,
                    fpagecount = mPagecount,
                    fpageindex = mPageindex,
                    data
                };
                return new JsonResult
                {
                    Data = obj,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
            catch
            {
                return new JsonResult
                {
                    Data = null,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
        }

    }
}